package com.jin.gulimall.auth.component;

import com.baidu.aip.face.AipFace;
import org.json.JSONObject;
import org.springframework.stereotype.Component;

import java.util.HashMap;

/**
 * 今今商城的人脸识别功能
 */
@Component
public class Face {

    public static final String APP_ID = "24261486";
    public static final String API_KEY = "i4zpli0bD4vacgPPY4zXWR9e";
    public static final String SECRET_KEY = "jYCgibn8MZxrn29Vd05HGsEgEcuTsA2b";

    public void faceImgAdd(String imageJson) {
        // 初始化一个AipFace
        AipFace client = new AipFace(APP_ID, API_KEY, SECRET_KEY);
        HashMap<String, String> options = new HashMap<String, String>();
        options.put("face_field", "age");

        // 调用接口
        String image = imageJson;
        String imageType = "BASE64";

        // 人脸检测
        JSONObject res = client.detect(image, imageType, options);
        System.out.println(res.toString(2));
    }
}
